//
//  PPUserAlbumPictureViewController.m
//  pickpic
//
//  Created by Jinxiao on 10/2/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPUserAlbumPictureViewController.h"

#import "PPAlbumPictureView.h"

@interface PPUserAlbumPictureViewController ()
@property (readwrite, nonatomic, assign) BOOL navigationBarHidden;
@end

@implementation PPUserAlbumPictureViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeTop;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRGBHex:0x00 alpha:0.8]] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}

- (Class)pictureViewClassAtIndex:(NSInteger)index {
    return [PPAlbumPictureView class];
}

- (void)pictureView:(PPAbstractPictureView *)pictureView didMoveToSuperView:(UIView *)superView {
    [super pictureView:pictureView didMoveToSuperView:superView];

    PPAbstractArtwork *artwork = pictureView.artwork;

    PPAlbumImageModel *image = [PPAlbumImageModel existingAlbumImageForImageID:artwork.imageID];

    ((PPAlbumPictureView *)pictureView).desc = image.desc;
}

- (void)pictureView:(PPAbstractPictureView *)pictureView didRecognizedSingleTapGesture:(UITapGestureRecognizer *)gesture {
    _navigationBarHidden = !_navigationBarHidden;
    
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        self.navigationController.navigationBar.alpha = _navigationBarHidden ? 0 : 1;
    } completion:nil];
}

@end
